<?php

namespace App\Admin\Controllers\Merchant;

use App\Models\SwtMerchantProfit;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Show;

class SwtMerchantProfitController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(SwtMerchantProfit::with('merchant'), function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');

            $grid->column('id')->sortable();
            $grid->column('order_id');
            $grid->column('merchant.name','商户名');
            $grid->column('profit','收益') -> display(function ($value) {
                return bcdiv($value, 100 ,2);
            });
            $grid->column('amount') -> display(function ($value) {
                return bcdiv($value, 100 ,2);
            });
            $grid->column('type')->using(['增加','减少'])->label(['success','danger']);
            $grid->column('desc');
            $grid->column('extra');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SwtMerchantProfit(), function (Show $show) {
            $show->field('id');
            $show->field('order_id');
            $show->field('merchant_id');
            $show->field('amount');
            $show->field('type');
            $show->field('desc');
            $show->field('extra');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SwtMerchantProfit(), function (Form $form) {
            $form->display('id');
            $form->text('order_id');
            $form->text('merchant_id');
            $form->text('amount');
            $form->text('type');
            $form->text('desc');
            $form->text('extra');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
